package org.example.serv.service;

import org.pf4j.JarPluginManager;
import org.pf4j.PluginManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
import java.nio.file.Paths;

@Component
public class PluginInit {

    @Bean
    public PluginManager initPluginManager() {
        Path pluginPath = Paths.get("d:/tmp/plugins");
        PluginManager pluginManager = new JarPluginManager(pluginPath);
        // 加载所有插件
        pluginManager.loadPlugins();

        // 启动指定插件
        //pluginManager.startPlugin("demo-plugin");
        pluginManager.startPlugins();

        return pluginManager;
    }
}
